import {Dict, Page, PageResult, R} from "@/api/common.ts";
import http from "@/utils/http.ts";
import {Role} from "@/api/role.ts";

enum Router {
    page = "users/page",
    dict = "users/dict",
    associate = "users/associate",
}

export interface User {
    id: number;
    userName: string;
    email: string;
    createTime: string;
    updateTime: string;
    status: number;
    roles: Role[];
}

export interface UserRolePost {
    userId: number;
    roleIds: number[];
}

/**
 * 用户分页查询
 * @param data
 */
export function pageUser(data: Page) {
    return http<R<PageResult<User>>>({
        url: Router.page,
        method: "post",
        data
    })
}

export function userDict() {
    return http<R<Dict[]>>({
        url: Router.dict,
        method: "get"
    })
}

export function associateRole(data: UserRolePost) {
    return http<R<null>>({
        url: Router.associate,
        method: "post",
        data
    })
}